// set
const fn = (arr) => {
  return Array.from(new Set(arr));
  //   return [...new Set(arr)];
};

// 遍历
const fn2 = (arr) => {
  let newArr = [];
  arr.forEach((item) => {
    if (!newArr.includes(item)) {
      newArr.push(item);
    }
  });
  return newArr;
};

// map
const fn3 = (arr) => {
  let mapping = new Map();
  let newArr = [];
  arr.forEach((item, index) => {
    if (!mapping.has(item)) {
      mapping.set(item, index);
      newArr.push(item);
    }
  });
  return newArr;
};

// indexOf
const fn4 = (arr) => {
  let newArr = [];
  arr.forEach((item) => {
    if (newArr.indexOf(item) === -1) {
      newArr.push(item);
    }
  });
  return newArr;
};

// 循环改变原数组
const fn5 = (arr) => {
  arr.sort();
  for (let i = 0; i < arr.length; i++) {
    if (arr[i] === arr[i + 1]) {
      arr.splice(i, 1);
      i--;
    }
  }
  return arr;
};

console.log(fn5([1, 4, 6, 2, 3, 4, 1, 6, 7, 3, 7, 4, 3, 6, 3, 6]));
